package testSocketUDP.viejo;

import java.net.UnknownHostException;

import utiles.Ip;

public class TestClienteCompleto {
	private TestClienteBroadcast clienteBroadcast;
	private TestClienteUDP clienteComunicacion;


	private String ipCliente= null;

	public TestClienteCompleto() {
		try {
			ipCliente= Ip.getIpV4();
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		}
	}

	private void iniciarFaseBroadcast() {
		clienteBroadcast= new TestClienteBroadcast(ipCliente);
		clienteBroadcast.start();
	}

	private void iniciarFaseComunicacion() {
		if(!clienteBroadcast.hayIpServidor()){
			try {
				synchronized(Thread.currentThread()){
					Thread.currentThread().wait();
				}				
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		clienteComunicacion= new TestClienteUDP(ipCliente, clienteBroadcast.getIpServidor());
		clienteComunicacion.start();
	}

	public static void main(String[] args) {
		TestClienteCompleto cliente= new TestClienteCompleto();
		cliente.iniciarFaseBroadcast();
		cliente.iniciarFaseComunicacion();
	}

}
